import { useLink } from '@h5app/sheep/hooks'

const { VITE_WE_CHAT_H5_APP_ID, VITE_WE_CHAT_H5_DOMAIN, VITE_DOMAIN } = import.meta.env
// const UserInfoScopeApi = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${VITE_WE_CHAT_H5_APP_ID}&redirect_uri=http%3A%2F%2Fdevelopers.weixin.qq.com&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`

export function useWechatH5() {
  const linkHooks = useLink()

  let UserInfoScopeUrl =
    linkHooks.assembleLink(`${VITE_WE_CHAT_H5_DOMAIN}/connect/oauth2/authorize`, {
      appid: VITE_WE_CHAT_H5_APP_ID,
      redirect_uri: encodeURIComponent(`${VITE_DOMAIN}/#/`),
      response_type: 'code',
      scope: 'snsapi_userinfo',
    }) + '#wechat_redirect'

  return { UserInfoScopeUrl }
}
